package com.ftg.learnmybatis.learnio;


import java.io.*;
import java.nio.charset.Charset;
import java.sql.SQLOutput;
import java.util.stream.Stream;

/**
 * 学习一下相关的文件的流操作（写入 | 读取）
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/3/13 上午10:08
 */
public class Example02 {

    /**
     * 读取文件操作
     * @param file  文件对象
     */
    public static void readFile(File file){
        //字节流 byte
        //字符流 char character
        InputStream is = null;
        OutputStream out = null;
        //目标文件
        File temp = new File("/home/kangjx/Desktop/abcTemp.txt");
        try {
            is = new FileInputStream(file);

            if(!temp.exists()){
                temp.createNewFile();
            }

            out = new FileOutputStream(temp);

            int n = 0;
            while((n = is.read()) != -1){
                out.write(n);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                is.close();
                out.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
//        流
    }

    public static void main(String[] args) {
        int c = '中';
        System.out.println(c);
//        int[] bs = new int[]{228,184,173};
//        System.out.println(new String(bs, 0, bs.length));
        readFile(new File("/home/kangjx/Desktop/abc.txt"));
    }

}
